from wordcloud import WordCloud
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
from json import load

desired_num = 80
mask_path = 'WordCloud/black.png'

with open('WordCloud/result.json', 'r', encoding='utf-8') as fr:
    counts = load(fr)

items = list(counts.items())

ciyun = [items[i][0] for i in range(desired_num)]

text_cut = '/'.join(ciyun)

mask = np.array(Image.open(mask_path))
cloud = WordCloud(mask=mask, background_color='white',
                  font_path='‪C:/Windows/Fonts/msyh.ttc', margin=2).generate(text_cut)

plt.imshow(cloud)
plt.axis('off')
plt.show()
